﻿#region

using System;
using System.Collections.Generic;
using DomainModel.Domain.Bases;
using DomainModel.Domain.Model.MessageTypeModel;
using DomainModel.Utils;

#endregion

namespace DomainModel.Domain.Model.MessageAssemblyModel
{
    public class MessageAssembly : Entity<MessageAssembly, MessageAssemblyId>
    {
        public MessageAssembly(MessageAssemblyId id) : base(id)
        {
            Validate.NotNull(id, "MessageAssemblyId must not be null");
        }

        public virtual string FileName { get; set; }

        public virtual string Name { get; set; }

        // nazwa, pod ktora dll-ka jest zapisana na dysku
        public virtual string LocalName { get; set; }
        // rozmiar
        public virtual long FileSize { get; set; }

        public virtual string Hash { get; set; }

        public virtual IList<MessageType> MessageTypesList { get; set; }

        //public Service UsedByService { get; set; }

        public virtual void AddMessageType(MessageType messageType)
        {
            if (MessageTypesList == null)
            {
                MessageTypesList = new List<MessageType>();
            }

            if (!MessageTypesList.Contains(messageType))
            {
                MessageTypesList.Add(messageType);
            }
        }

        protected internal virtual MessageType FindMessageType(String typeName)
        {
            if (MessageTypesList != null)
            {
                foreach (var messageType in MessageTypesList)
                {
                    if (messageType.Name.Equals(typeName))
                    {
                        return messageType;
                    }
                }
            }

            return null;
        }

        protected internal MessageAssembly()
        {
        }
    }
}